package com.mys.maggie.redis.api.util;

import com.mys.maggie.redis.api.enums.SerializerTypeEnum;
import org.springframework.data.redis.serializer.*;

/**
 * desc: 序列化帮助类
 * date:2020/10/21 20:05
 */
public class RedisSerializerUtil {

    /**
     * 获取序列方式
     * @param type 类型枚举
     * @param Jackson2JsonRedisSerializer jackson2
     * @return RedisSerializer
     */
    public static RedisSerializer getRedisSerializer(Integer type, RedisSerializer Jackson2JsonRedisSerializer){
        SerializerTypeEnum typeEnum = SerializerTypeEnum.getSerializerEnum( type );
        RedisSerializer stringSerializer = new StringRedisSerializer();
        switch (typeEnum){

            case StringRedisSerializerEnum: //string
                return stringSerializer;
            case Jackson2JsonRedisSerializerEnum: //Jackson2Json
                return Jackson2JsonRedisSerializer;
            case GenericToStringSerializerEnum: //GenericToStringSerializer
                return new GenericToStringSerializer<>(String.class);
            case JdkSerializationRedisSerializerEnum: //JdkSerializationRedisSerializer
                return new JdkSerializationRedisSerializer();
            case GenericJackson2JsonRedisSerializerEnum: //GenericJackson2JsonRedisSerializer
                return new GenericJackson2JsonRedisSerializer();
            default:
                return stringSerializer; //默认String
        }

    }

















}
